package c.i.b.a.c;

import com.huawei.agconnect.exception.AGCServerException;
import com.huawei.hms.android.HwBuildEx.VersionCodes;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class a {
    public static String a(String str, byte[] bArr) {
        URL url;
        try {
            url = new URL(str);
        } catch (Throwable unused) {
            url = null;
        }
        str = "application/octet-stream";
        try {
            "https".equals(url.getProtocol().toLowerCase());
            HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
            httpURLConnection.setRequestProperty("Content-Type", str);
            httpURLConnection.setConnectTimeout(VersionCodes.CUR_DEVELOPMENT);
            httpURLConnection.setReadTimeout(5000);
            httpURLConnection.setDoOutput(true);
            httpURLConnection.setRequestMethod("POST");
            OutputStream outputStream = httpURLConnection.getOutputStream();
            outputStream.write(bArr);
            outputStream.flush();
            if (httpURLConnection.getResponseCode() != AGCServerException.OK) {
                return String.format("{\"code\":%d}", new Object[]{Integer.valueOf(httpURLConnection.getResponseCode())});
            }
            InputStream inputStream = httpURLConnection.getInputStream();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "utf-8"));
            StringBuilder stringBuilder = new StringBuilder();
            while (true) {
                String readLine = bufferedReader.readLine();
                if (readLine != null) {
                    stringBuilder.append(readLine);
                } else {
                    inputStream.close();
                    outputStream.close();
                    return stringBuilder.toString();
                }
            }
        } catch (Throwable unused2) {
            return "";
        }
    }
}
